package edu.gxnu.cetcdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.gxnu.cetcdemo.mapper.MaintainMapper;
import edu.gxnu.cetcdemo.pojo.Maintain;
import edu.gxnu.cetcdemo.service.MaintainService;
import edu.gxnu.cetcdemo.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Uplifted
* @description 针对表【maintain】的数据库操作Service实现
* @createDate 2024-04-17 12:30:19
*/
@Service
public class MaintainServiceImpl extends ServiceImpl<MaintainMapper, Maintain>
    implements MaintainService{

    @Autowired
    private MaintainMapper maintainMapper;

    @Override
    public Result queryMaintainList() {
        Map data = new HashMap();
        List<Maintain> maintainList = maintainMapper.selectList(null);
        data.put("maintainList", maintainList);
        return Result.build(200, "成功查询所有维修信息", data);
    }

    @Override
    public Result addMaintain(Maintain maintain) {
        maintainMapper.insert(maintain);
        return Result.build(200, "维修信息添加成功");
    }

    @Override
    public Result updateMaintain(Maintain maintain) {
        maintainMapper.update(maintain, new LambdaQueryWrapper<Maintain>().eq(Maintain::getMaintainId, maintain.getMaintainId()));
        return Result.build(200, "维修信息更新成功");
    }

    @Override
    public Result delMaintain(long id) {
        maintainMapper.delete(new LambdaQueryWrapper<Maintain>().eq(Maintain::getMaintainId, id));
        return Result.build(200, "维修信息删除成功");
    }
}




